package com.qbm.association.bean;

import lombok.Getter;

/**
 *      主要用来返回数据到前端
 * @author chenchen
 *
 */
@Getter
public final class ResultBean {

    /**
     * 返回的状态码
     */
    private Integer code;
    /**
     * 是否成功
     */
    private boolean successed;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回的数据
     */
    private Object data;

    private ResultBean() {

    }

    /**
     * 私有的构建方法
     * @param code
     * @param successed
     * @param message
     * @param data
     */
    private ResultBean(Integer code, boolean successed, String message, Object data) {
        this.code = code;
        this.successed = successed;
        this.message = message;
        this.data = data;
    }

    public static ResultBean success() {
        return new ResultBean(HttpStatus.SUCCESS.getCode(), true, "操作成功", null);
    }

    public static ResultBean success(String message) {
        return new ResultBean(HttpStatus.SUCCESS.getCode(), true, message, null);
    }

    public static ResultBean success(Object data) {
        return new ResultBean(HttpStatus.SUCCESS.getCode(), true, "成功返回数据", data);
    }

    public static ResultBean success(Object data, String message) {
        return new ResultBean(HttpStatus.SUCCESS.getCode(), true, message, data);
    }

    public static ResultBean fail(String message) {
        return new ResultBean(HttpStatus.FAIL.getCode(), false, message, null);
    }

    public static ResultBean overDue(String message) {
        return new ResultBean(HttpStatus.OVERDUE.getCode(), false, message, null);
    }
}
